# -*- coding: utf-8 -*-

'''
Created on 05.06.2011

@author: mutius
'''
import wx
from wx._core import EVT_BUTTON

class CreateBaseDialog(wx.Dialog):
    def __init__(self, parent, id):
        wx.Dialog.__init__(self, parent, id)
        self.checkbox_1 = wx.CheckBox(self, -1, u"использовать юникод")
        self.static_line_1 = wx.StaticLine(self, -1)
        self.label_2 = wx.StaticText(self, -1, u"название базы")
        self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_PROCESS_ENTER)
        self.button_1 = wx.Button(self, -1, "Ok")

        self.checkbox_1.SetValue(True)
        self.command = str()
        self.SetTitle(u"Создание новой базы")
        self.SetSize((350, 180))
        
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.checkbox_1, 0, wx.LEFT|wx.TOP, 10)
        sizer_1.Add(self.static_line_1, 0, wx.ALL|wx.EXPAND, 10)
        sizer_1.Add(self.label_2, 0, wx.LEFT|wx.TOP, 10)
        sizer_1.Add(self.text_ctrl_1, 0, wx.ALL|wx.EXPAND, 10)
        sizer_1.Add(self.button_1, 0, wx.RIGHT|wx.BOTTOM|wx.ALIGN_RIGHT, 10)
        self.SetSizer(sizer_1)
        self.Layout()
        self.Bind(EVT_BUTTON, self.onOk, self.button_1)
        
    def onOk(self, event):
        name = self.text_ctrl_1.GetValue()
        print "ok pushed"
        if len(name) == 0:
            message = wx.MessageDialog(None, u"некорректное название", u"Message", wx.ICON_HAND)
            message.ShowModal()
            message.Destroy()
        else:
            self.command = u"CREATE DATABASE " + name
            if self.checkbox_1.GetValue():
                self.command = self.command + u" CHARACTER SET utf8"
            self.Close()